import java.util.Scanner;

/**
 * 用户服务
 *
 * @author yuwei
 * @date 16:50 2024/4/24
 */
public class positionManage {
    public static Boolean find(String name)
    {
        for (Position position : positionTable.positions) {
            if (position.getDepartment_name().equals(name))
            {
                return true;
            }
        }
        return false;
    }

    public static void delete()
    {
        if(positionTable.positions.size()==0){
            System.out.println("    无任何数据 ");
            return;
        }
       for(int i =1; i<= positionTable.positions.size();i++){
           System.out.println(i+"."+positionTable.positions.toArray()[i-1]);
       }
       System.out.println("请输入要删除的职位编号");
       Scanner scanner = new Scanner(System.in);
       int num = scanner.nextInt();
       if (num>0&&num<=positionTable.positions.size())
       {
           Position position = (Position)positionTable.positions.toArray()[num-1];
           if(employeeManage.find(position.getPositionName())){
               System.out.println("该职位下有员工，不能删除");
               return;
           }
           positionTable.positions.remove(num-1);
           System.out.println("删除成功");
       }
       else
       {
           System.out.println("输入错误");
       }
    }
    public static void add()
    {
        if(departmentTable.departments.size()==0){
            System.out.println("还未添加部门");
            return;
        }
        departmentManage.show();
        System.out.println("--添加岗位--");
        departmentManage.show();
        System.out.println("输入部门名称");
        Scanner scan = new Scanner(System.in);
        String name = scan.next();
        System.out.println("输入岗位名称");
        String name2 = scan.next();

        if (positionTable.positions.add(new Position(name,name2)))
        {
            System.out.println("添加成功");
        }
        else
        {
            System.out.println("添加失败,该岗位可能已经存在");
        }
    }
    public static void show() {
        positionTable.positions.forEach(System.out::println);
    }
}
